﻿Imports System.Windows.Forms
Imports ICtagControl.modDataGridViewCustomize


Module modDataGridViewCustomize

#Region "BarCode"

    Public Class DataGridViewBarCodeColumn
        Inherits DataGridViewColumn

        Public Sub New()
            MyBase.New(New DataGridViewBarCodeCell())
        End Sub

        Public Overrides Property CellTemplate() As DataGridViewCell
            Get
                Return MyBase.CellTemplate
            End Get
            Set(ByVal value As DataGridViewCell)

                ' Ensure that the cell used for the template is a CalendarCell.
                If (value IsNot Nothing) AndAlso _
                    Not value.GetType().IsAssignableFrom(GetType(DataGridViewBarCodeCell)) _
                    Then
                    Throw New InvalidCastException("Must be a CalendarCell")
                End If
                MyBase.CellTemplate = value

            End Set
        End Property

    End Class

    Public Class DataGridViewBarCodeCell
        Inherits DataGridViewTextBoxCell

        Private ctl As BarCodeEditingControl

        Public Sub New()
            ' Use the short date format.
            'Me.Style.Format = "d"
        End Sub

        Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
            ByVal initialFormattedValue As Object, _
            ByVal dataGridViewCellStyle As DataGridViewCellStyle)

            ' Set the value of the editing control to the current cell value.
            MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
                dataGridViewCellStyle)

            ctl =  CType(DataGridView.EditingControl, BarCodeEditingControl)

            ' Use the default row value when Value property is null.
            If IsDBNull(Me.Value) OrElse (Me.Value Is Nothing) Then
                ctl.Text = String.Empty
            Else
                ctl.Text = Value
            End If
        End Sub

        Public Overrides ReadOnly Property EditType() As Type
            Get
                ' Return the type of the editing control that CalendarCell uses.
                Return GetType(BarCodeEditingControl)
            End Get
        End Property

        Public Overrides ReadOnly Property ValueType() As Type
            Get
                ' Return the type of the value that CalendarCell contains.
                Return GetType(String)
            End Get
        End Property

        Public Overrides ReadOnly Property DefaultNewRowValue() As Object
            Get
                ' Use the current date and time as the default value.
                Return String.Empty
            End Get
        End Property

    End Class

    Class BarCodeEditingControl
        Inherits BarCodeCell
        Implements IDataGridViewEditingControl

        Private dataGridViewControl As DataGridView
        Private valueIsChanged As Boolean = False
        Private rowIndexNum As Integer

        Public Sub New()
            'Me.Format = DateTimePickerFormat.Short
        End Sub

        Public Property EditingControlFormattedValue() As Object _
            Implements IDataGridViewEditingControl.EditingControlFormattedValue

            Get
                Return Me.Text
            End Get

            Set(ByVal value As Object)
                Try
                    ' This will throw an exception of the string is 
                    ' null, empty, or not in the format of a date.
                    Me.Text = value
                Catch
                    ' In the case of an exception, just use the default
                    ' value so we're not left with a null value.
                    Me.Text = String.Empty
                End Try
            End Set

        End Property

        Public Function GetEditingControlFormattedValue(ByVal context _
            As DataGridViewDataErrorContexts) As Object _
            Implements IDataGridViewEditingControl.GetEditingControlFormattedValue

            Return Me.Text

        End Function

        Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As  _
            DataGridViewCellStyle) _
            Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl

            Me.Font = dataGridViewCellStyle.Font

        End Sub

        Public Property EditingControlRowIndex() As Integer _
            Implements IDataGridViewEditingControl.EditingControlRowIndex

            Get
                Return rowIndexNum
            End Get
            Set(ByVal value As Integer)
                rowIndexNum = value
            End Set

        End Property

        Public Function EditingControlWantsInputKey(ByVal key As Keys, _
            ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
            Implements IDataGridViewEditingControl.EditingControlWantsInputKey

            ' Let the DateTimePicker handle the keys listed.
            Select Case key And Keys.KeyCode
                Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
                    Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

                    Return True

                Case Else
                    Return Not dataGridViewWantsInputKey
            End Select

        End Function

        Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
            Implements IDataGridViewEditingControl.PrepareEditingControlForEdit

            Me.KeepEdit = True
            Me.BeginInput()

        End Sub

        Public ReadOnly Property RepositionEditingControlOnValueChange() _
            As Boolean Implements _
            IDataGridViewEditingControl.RepositionEditingControlOnValueChange

            Get
                Return False
            End Get

        End Property

        Public Property EditingControlDataGridView() As DataGridView _
            Implements IDataGridViewEditingControl.EditingControlDataGridView

            Get
                Return dataGridViewControl
            End Get
            Set(ByVal value As DataGridView)
                dataGridViewControl = value
            End Set

        End Property

        Public Property EditingControlValueChanged() As Boolean _
            Implements IDataGridViewEditingControl.EditingControlValueChanged

            Get
                Return valueIsChanged
            End Get
            Set(ByVal value As Boolean)
                valueIsChanged = value
            End Set

        End Property

        Public ReadOnly Property EditingControlCursor() As Cursor _
            Implements IDataGridViewEditingControl.EditingPanelCursor

            Get
                Return Cursors.IBeam
            End Get

        End Property

        Protected Overrides Sub txtInput_LostFocus(ByVal sender As Object, ByVal e As EventArgs)

            MyBase.txtInput_LostFocus(sender, e)
            ' Notify the DataGridView that the contents of the cell have changed.
            valueIsChanged = True
            Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            Me.EditingControlDataGridView.CurrentCell.Value = Me.Text

            If Me.EditingControlDataGridView.IsCurrentCellInEditMode Then
                'Me.EditingControlDataGridView.EndEdit()
                Me.EditingControlDataGridView.ClearSelection()
            End If

        End Sub

    End Class
#End Region

#Region "Tenkey"

    Public Class DataGridViewTenkeyColumn
        Inherits DataGridViewColumn

        Public Sub New()
            MyBase.New(New DataGridViewTenkeyCell())
        End Sub

        Public Overrides Property CellTemplate() As DataGridViewCell
            Get
                Return MyBase.CellTemplate
            End Get
            Set(ByVal value As DataGridViewCell)

                ' Ensure that the cell used for the template is a CalendarCell.
                If (value IsNot Nothing) AndAlso _
                    Not value.GetType().IsAssignableFrom(GetType(DataGridViewTenkeyCell)) _
                    Then
                    Throw New InvalidCastException("Must be a CalendarCell")
                End If
                MyBase.CellTemplate = value

            End Set
        End Property

    End Class

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Class DataGridViewTenkeyCell
        Inherits DataGridViewTextBoxCell

        Private ctl As TenkeyEditingControl

        Public Sub New()
            ' Use the short date format.
            'Me.Style.Format = "d"
        End Sub

        Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
            ByVal initialFormattedValue As Object, _
            ByVal dataGridViewCellStyle As DataGridViewCellStyle)

            ' Set the value of the editing control to the current cell value.
            MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
                dataGridViewCellStyle)

            ctl = CType(DataGridView.EditingControl, TenkeyEditingControl)

            ' Use the default row value when Value property is null.
            If IsDBNull(Me.Value) OrElse (Me.Value Is Nothing) Then
                ctl.Text = String.Empty
            Else
                ctl.Text = Value
            End If
        End Sub

        Public Overrides ReadOnly Property EditType() As Type
            Get
                ' Return the type of the editing control that CalendarCell uses.
                Return GetType(TenkeyEditingControl)
            End Get
        End Property

        Public Overrides ReadOnly Property ValueType() As Type
            Get
                ' Return the type of the value that CalendarCell contains.
                Return GetType(String)
            End Get
        End Property

        Public Overrides ReadOnly Property DefaultNewRowValue() As Object
            Get
                ' Use the current date and time as the default value.
                Return String.Empty
            End Get
        End Property

    End Class

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Class TenkeyEditingControl
        Inherits TenKeyLabel
        Implements IDataGridViewEditingControl

        Private dataGridViewControl As DataGridView
        Private valueIsChanged As Boolean = False
        Private rowIndexNum As Integer

        Public Sub New()
            'Me.Format = DateTimePickerFormat.Short
        End Sub

        Public Property EditingControlFormattedValue() As Object _
            Implements IDataGridViewEditingControl.EditingControlFormattedValue

            Get
                Return Me.Text
            End Get

            Set(ByVal value As Object)
                Try
                    ' This will throw an exception of the string is 
                    ' null, empty, or not in the format of a date.
                    Me.Text = value
                Catch
                    ' In the case of an exception, just use the default
                    ' value so we're not left with a null value.
                    Me.Text = String.Empty
                End Try
            End Set

        End Property

        Public Function GetEditingControlFormattedValue(ByVal context _
            As DataGridViewDataErrorContexts) As Object _
            Implements IDataGridViewEditingControl.GetEditingControlFormattedValue

            Return Me.Text

        End Function

        Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As  _
            DataGridViewCellStyle) _
            Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl

            Me.Font = dataGridViewCellStyle.Font

        End Sub

        Public Property EditingControlRowIndex() As Integer _
            Implements IDataGridViewEditingControl.EditingControlRowIndex

            Get
                Return rowIndexNum
            End Get
            Set(ByVal value As Integer)
                rowIndexNum = value
            End Set

        End Property

        Public Function EditingControlWantsInputKey(ByVal key As Keys, _
            ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
            Implements IDataGridViewEditingControl.EditingControlWantsInputKey

            ' Let the DateTimePicker handle the keys listed.
            Select Case key And Keys.KeyCode
                Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
                    Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

                    Return True

                Case Else
                    Return Not dataGridViewWantsInputKey
            End Select

        End Function

        Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
            Implements IDataGridViewEditingControl.PrepareEditingControlForEdit

            Me.Text = Me.EditingControlDataGridView.CurrentCell.Value.ToString
            Me.TextAlign = ContentAlignment.MiddleCenter

            If selectAll Then 'UPD MIAOJF 20200106 If not selectAll Then
                Dim pt2Screen As Point = Me.PointToScreen(New Point(0, 0))
                'frmKindSwapMold.CallTenkey(Me, pt2Screen.X - MyBase.Left, pt2Screen.Y - MyBase.Top)
                CallTenkey(Me, pt2Screen.X - MyBase.Left, pt2Screen.Y - MyBase.Top)
            End If

        End Sub
        Public Sub CallTenkey(ByRef lblInput As TenKeyLabel, Optional ByVal iLeft As Integer = 0, Optional ByVal iTop As Integer = 0)
            'Me.Focus()
            Dim tk As New TenKey(lblInput)
            'Dim pos As New Point(iLeft, iTop)
            'iDifTop = lblInput.Parent.Top
            'tk.Top = iTop + lblInput.Height / 2
            'tk.Left = iLeft
            'If tk.Right > Me.Width Then
            '    tk.Left = Me.Width - tk.Width + 180
            'End If
            'If tk.Bottom > Me.Height Then
            '    tk.Top = iTop - tk.Height - lblInput.Height + 90
            'End If

            'tk.Location = pos
            Me.Parent.Parent.Controls.Add(tk)
            tk.Top = 50 'LblInput.Top + 60
            tk.Left = 300 ' lblInput.Left + 40
            'tk.Visible = True
        End Sub
        Public ReadOnly Property RepositionEditingControlOnValueChange() _
            As Boolean Implements _
            IDataGridViewEditingControl.RepositionEditingControlOnValueChange

            Get
                Return False
            End Get

        End Property

        Public Property EditingControlDataGridView() As DataGridView _
            Implements IDataGridViewEditingControl.EditingControlDataGridView

            Get
                Return dataGridViewControl
            End Get
            Set(ByVal value As DataGridView)
                dataGridViewControl = value
            End Set

        End Property

        Public Property EditingControlValueChanged() As Boolean _
            Implements IDataGridViewEditingControl.EditingControlValueChanged

            Get
                Return valueIsChanged
            End Get
            Set(ByVal value As Boolean)
                valueIsChanged = value
            End Set

        End Property

        Public ReadOnly Property EditingControlCursor() As Cursor _
            Implements IDataGridViewEditingControl.EditingPanelCursor

            Get
                Return Cursors.IBeam
            End Get

        End Property

        Private Sub MyBase_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Click
            'Dim pt2Screen As Point = Me.PointToScreen(New Point(0, 0))
            'frmKindSwapMold.CallTenkey(Me, pt2Screen.X - MyBase.Left, pt2Screen.Y - MyBase.Top)
        End Sub

        Private Sub MyBase_EndEdit(ByVal sender As Object) Handles MyBase.InputCompleted
            ' Notify the DataGridView that the contents of the cell have changed.
            valueIsChanged = True
            Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            Me.EditingControlDataGridView.CurrentCell.Value = Me.Text

            If Me.EditingControlDataGridView.IsCurrentCellInEditMode Then
                Me.EditingControlDataGridView.EndEdit()
                Me.EditingControlDataGridView.ClearSelection()
            End If
        End Sub
        'Protected Overrides Sub txtInput_LostFocus(ByVal sender As Object, ByVal e As EventArgs)

        '    MyBase.txtInput_LostFocus(sender, e)
        '    ' Notify the DataGridView that the contents of the cell have changed.
        '    valueIsChanged = True
        '    Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
        '    Me.EditingControlDataGridView.CurrentCell.Value = Me.Text

        '    If Me.EditingControlDataGridView.IsCurrentCellInEditMode Then
        '        'Me.EditingControlDataGridView.EndEdit()
        '        Me.EditingControlDataGridView.ClearSelection()
        '    End If

        'End Sub

    End Class
#End Region

#Region "OK/NG"
    Public Class DataGridViewOkNgColumn
        Inherits DataGridViewColumn

        Public Sub New()
            'MyBase.New(New DataGridViewOkNgCell())
            Me.CellTemplate = New DataGridViewOkNgCell
        End Sub

        Public Overrides Property CellTemplate() As DataGridViewCell
            Get
                Return MyBase.CellTemplate
            End Get
            Set(ByVal value As DataGridViewCell)

                ' Ensure that the cell used for the template is a CalendarCell.
                If (value IsNot Nothing) AndAlso _
                    Not value.GetType().IsAssignableFrom(GetType(DataGridViewOkNgCell)) _
                    Then
                    Throw New InvalidCastException("Must be a DataGridViewOkNgCell")
                End If
                MyBase.CellTemplate = value

            End Set
        End Property

    End Class


    ''' <summary>
    ''' OK/NG
    ''' </summary>
    ''' <remarks></remarks>
    Public Class DataGridViewOkNgCell
        Inherits DataGridViewTextBoxCell

        Private WithEvents ctl As OkNgControl

        Public Property Text As String
            Get
                Return ctl.Value
            End Get
            Set(ByVal value As String)
                ctl.Value = value
            End Set
        End Property

        Public Sub New()
            ' Use the short date format.
            'Me.Style.Format = "d"
        End Sub

        'Public Overrides ReadOnly Property FormattedValueType As System.Type
        '    Get
        '        Return GetType(String)
        '    End Get
        'End Property

        Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
            ByVal initialFormattedValue As Object, _
            ByVal dataGridViewCellStyle As DataGridViewCellStyle)

            ' Set the value of the editing control to the current cell value.
            MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
                dataGridViewCellStyle)

            ctl = CType(DataGridView.EditingControl, OkNgControl)

            ' Use the default row value when Value property is null.
            If IsDBNull(Me.Value) OrElse (Me.Value Is Nothing) Then
                ctl.Value = String.Empty
            Else
                ctl.Value = Me.Value
            End If
        End Sub

        Public Overrides ReadOnly Property EditType() As Type
            Get
                ' Return the type of the editing control that CalendarCell uses.
                Return GetType(OkNgControl)
            End Get
        End Property

        Public Overrides ReadOnly Property DefaultNewRowValue() As Object
            Get
                ' Use the current date and time as the default value.
                Return String.Empty
            End Get
        End Property

        'Private Sub ctl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctl.Click
        '    Me.Value = ctl.Value
        'End Sub
    End Class


    ''' <summary>
    ''' OK/NGボタン
    ''' </summary>
    ''' <remarks></remarks>
    Class OkNgControl
        Inherits OkNgCell
        Implements IDataGridViewEditingControl

        Private dataGridViewControl As DataGridView
        Private valueIsChanged As Boolean = False
        Private rowIndexNum As Integer

        Public Sub New()
            MyBase.Focus()
        End Sub

        Public Property EditingControlFormattedValue() As Object _
            Implements IDataGridViewEditingControl.EditingControlFormattedValue

            Get
                Return Me.Value
            End Get

            Set(ByVal value As Object)
                Try
                    ' This will throw an exception of the string is 
                    ' null, empty, or not in the format of a date.
                    Me.Value = value
                Catch
                    ' In the case of an exception, just use the default
                    ' value so we're not left with a null value.

                End Try
            End Set

        End Property

        Public Function GetEditingControlFormattedValue(ByVal context _
            As DataGridViewDataErrorContexts) As Object _
            Implements IDataGridViewEditingControl.GetEditingControlFormattedValue

            Return Me.Value()

        End Function

        Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As  _
            DataGridViewCellStyle) _
            Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl

            'Me.Font = dataGridViewCellStyle.Font
            'Me.CalendarForeColor = dataGridViewCellStyle.ForeColor
            'Me.CalendarMonthBackground = dataGridViewCellStyle.BackColor

        End Sub

        Public Property EditingControlRowIndex() As Integer _
            Implements IDataGridViewEditingControl.EditingControlRowIndex

            Get
                Return rowIndexNum
            End Get
            Set(ByVal value As Integer)
                rowIndexNum = value
            End Set

        End Property

        Public Function EditingControlWantsInputKey(ByVal key As Keys, _
            ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
            Implements IDataGridViewEditingControl.EditingControlWantsInputKey

            ' Let the DateTimePicker handle the keys listed.
            Select Case key And Keys.KeyCode
                Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
                    Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

                    Return True

                Case Else
                    Return Not dataGridViewWantsInputKey
            End Select

        End Function

        Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
            Implements IDataGridViewEditingControl.PrepareEditingControlForEdit

            Me.Value = Me.EditingControlDataGridView.CurrentCell.Value

        End Sub

        Public ReadOnly Property RepositionEditingControlOnValueChange() _
            As Boolean Implements _
            IDataGridViewEditingControl.RepositionEditingControlOnValueChange

            Get
                Return False
            End Get

        End Property

        Public Property EditingControlDataGridView() As DataGridView _
            Implements IDataGridViewEditingControl.EditingControlDataGridView

            Get
                Return dataGridViewControl
            End Get
            Set(ByVal value As DataGridView)
                dataGridViewControl = value
            End Set

        End Property

        Public Property EditingControlValueChanged() As Boolean _
            Implements IDataGridViewEditingControl.EditingControlValueChanged

            Get
                Return valueIsChanged
            End Get
            Set(ByVal value As Boolean)
                valueIsChanged = value
            End Set

        End Property

        Public ReadOnly Property EditingControlCursor() As Cursor _
            Implements IDataGridViewEditingControl.EditingPanelCursor

            Get
                Return Nothing
            End Get

        End Property

        Protected Overrides Sub btnOK_Click(ByVal sender As Object, ByVal eventargs As EventArgs)

            MyBase.btnOK_Click(sender, eventargs)

            valueIsChanged = True
            Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            Me.EditingControlDataGridView.CurrentCell.Value = Me.Value

            Me.EditingControlDataGridView.EndEdit()
        End Sub

        Protected Overrides Sub btnNG_Click(ByVal sender As Object, ByVal eventargs As EventArgs)

            MyBase.btnNG_Click(sender, eventargs)

            valueIsChanged = True
            Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            Me.EditingControlDataGridView.CurrentCell.Value = Me.Value

            Me.EditingControlDataGridView.EndEdit()
        End Sub

    End Class
#End Region

#Region "Result"

    Public Class DataGridViewResultColumn
        Inherits DataGridViewColumn

        Public Sub New()
            MyBase.New(New DataGridViewResultCell())
        End Sub

        Public Overrides Property CellTemplate() As DataGridViewCell
            Get
                Return MyBase.CellTemplate
            End Get
            Set(ByVal value As DataGridViewCell)

                ' Ensure that the cell used for the template is a CalendarCell.
                If (value IsNot Nothing) AndAlso _
                    Not value.GetType().IsAssignableFrom(GetType(DataGridViewResultCell)) _
                    Then
                    Throw New InvalidCastException("Must be a CalendarCell")
                End If
                MyBase.CellTemplate = value

            End Set
        End Property

    End Class

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Class DataGridViewResultCell
        Inherits DataGridViewTextBoxCell

        Private WithEvents ctl As ResultEditingControl

        Public Sub New()
            ' Use the short date format.
            'Me.Style.Format = "d"
        End Sub

        Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
            ByVal initialFormattedValue As Object, _
            ByVal dataGridViewCellStyle As DataGridViewCellStyle)

            ' Set the value of the editing control to the current cell value.
            MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _
                dataGridViewCellStyle)

            ctl = CType(DataGridView.EditingControl, ResultEditingControl)

            ' Use the default row value when Value property is null.
            If IsDBNull(Me.Value) OrElse (Me.Value Is Nothing) Then
                ctl.Text = String.Empty
            Else
                ctl.Text = Value
            End If
        End Sub

        Public Overrides ReadOnly Property EditType() As Type
            Get
                ' Return the type of the editing control that CalendarCell uses.
                Return GetType(ResultEditingControl)
            End Get
        End Property

        Public Overrides ReadOnly Property ValueType() As Type
            Get
                ' Return the type of the value that CalendarCell contains.
                Return GetType(String)
            End Get
        End Property

        Public Overrides ReadOnly Property DefaultNewRowValue() As Object
            Get
                ' Use the current date and time as the default value.
                Return String.Empty
            End Get
        End Property

        Private Sub Ctl_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ctl.Click
            Dim pt2Screen As Point = ctl.PointToScreen(New Point(0, 0))
            frmKindSwapMold.CallTenkey(ctl.InputLabel, pt2Screen.X - ctl.Left, pt2Screen.Y - ctl.Top)
        End Sub

        Private Sub Ctl_EndInput(ByVal sender As Object, ByVal e As EventArgs) Handles ctl.InputCompleted
            'valueIsChanged = True
            'ctl.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            'ctl.EditingControlDataGridView.CurrentCell.Value = Me.Text

            'If Me.EditingControlDataGridView.IsCurrentCellInEditMode Then
            '    Me.EditingControlDataGridView.EndEdit()
            '    Me.EditingControlDataGridView.ClearSelection()
            'End If
        End Sub

    End Class

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Class ResultEditingControl
        Inherits AppearenceResult
        Implements IDataGridViewEditingControl

        Private dataGridViewControl As DataGridView
        Private valueIsChanged As Boolean = False
        Private rowIndexNum As Integer

        Public Sub New()
            'Me.Format = DateTimePickerFormat.Short
        End Sub

        Public Property EditingControlFormattedValue() As Object _
            Implements IDataGridViewEditingControl.EditingControlFormattedValue

            Get
                Return Me.Text
            End Get

            Set(ByVal value As Object)
                Try
                    ' This will throw an exception of the string is 
                    ' null, empty, or not in the format of a date.
                    Me.Text = value
                Catch
                    ' In the case of an exception, just use the default
                    ' value so we're not left with a null value.
                    Me.Text = String.Empty
                End Try
            End Set

        End Property

        Public Function GetEditingControlFormattedValue(ByVal context _
            As DataGridViewDataErrorContexts) As Object _
            Implements IDataGridViewEditingControl.GetEditingControlFormattedValue

            Return Me.Text

        End Function

        Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As  _
            DataGridViewCellStyle) _
            Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl

            Me.Font = dataGridViewCellStyle.Font

        End Sub

        Public Property EditingControlRowIndex() As Integer _
            Implements IDataGridViewEditingControl.EditingControlRowIndex

            Get
                Return rowIndexNum
            End Get
            Set(ByVal value As Integer)
                rowIndexNum = value
            End Set

        End Property

        Public Function EditingControlWantsInputKey(ByVal key As Keys, _
            ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
            Implements IDataGridViewEditingControl.EditingControlWantsInputKey

            ' Let the DateTimePicker handle the keys listed.
            Select Case key And Keys.KeyCode
                Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
                    Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

                    Return True

                Case Else
                    Return Not dataGridViewWantsInputKey
            End Select

        End Function

        Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
            Implements IDataGridViewEditingControl.PrepareEditingControlForEdit

            Me.Text = Me.EditingControlDataGridView.CurrentCell.Value.ToString
            Me.EditingControlDataGridView.Columns(Me.EditingControlDataGridView.CurrentCell.ColumnIndex).Width = 300
            'If Not selectAll Then
            '    Dim pt2Screen As Point = Me.PointToScreen(New Point(0, 0))
            '    frmKindSwapMold.CallTenkey(Me.InputLabel, pt2Screen.X - MyBase.Left, pt2Screen.Y - MyBase.Top)
            'End If

        End Sub

        Public ReadOnly Property RepositionEditingControlOnValueChange() _
            As Boolean Implements _
            IDataGridViewEditingControl.RepositionEditingControlOnValueChange

            Get
                Return False
            End Get

        End Property

        Public Property EditingControlDataGridView() As DataGridView _
            Implements IDataGridViewEditingControl.EditingControlDataGridView

            Get
                Return dataGridViewControl
            End Get
            Set(ByVal value As DataGridView)
                dataGridViewControl = value
            End Set

        End Property

        Public Property EditingControlValueChanged() As Boolean _
            Implements IDataGridViewEditingControl.EditingControlValueChanged

            Get
                Return valueIsChanged
            End Get
            Set(ByVal value As Boolean)
                valueIsChanged = value
            End Set

        End Property

        Public ReadOnly Property EditingControlCursor() As Cursor _
            Implements IDataGridViewEditingControl.EditingPanelCursor

            Get
                Return Cursors.IBeam
            End Get

        End Property

        Private Sub MyBase_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Click
            'Dim pt2Screen As Point = Me.PointToScreen(New Point(0, 0))
            'frmKindSwapMold.CallResult(Me, pt2Screen.X - MyBase.Left, pt2Screen.Y - MyBase.Top)
        End Sub

        Private Sub MyBase_EndEdit(ByVal sender As Object) 'Handles MyBase.InputCompleted
            ' Notify the DataGridView that the contents of the cell have changed.
            valueIsChanged = True
            Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            Me.EditingControlDataGridView.CurrentCell.Value = Me.Text

            If Me.EditingControlDataGridView.IsCurrentCellInEditMode Then
                Me.EditingControlDataGridView.EndEdit()
                Me.EditingControlDataGridView.ClearSelection()
            End If
        End Sub

        Public Overrides Sub On_InputCompleted()

            ' Notify the DataGridView that the contents of the cell have changed.
            valueIsChanged = True
            Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
            Me.EditingControlDataGridView.CurrentCell.Value = Me.Text

            If Me.EditingControlDataGridView.IsCurrentCellInEditMode Then
                Me.EditingControlDataGridView.EndEdit()
                Me.EditingControlDataGridView.ClearSelection()
                Me.EditingControlDataGridView.Columns(Me.EditingControlDataGridView.CurrentCell.ColumnIndex).Width = 100
            End If

        End Sub

    End Class
#End Region

End Module
